<?php
/*
 * СПВ
 **/
class SP_Helper_PassGenerator
{
	static private $_instance = null;
	protected static $length=6;
	protected static $alphabet=array('a','b','c','d','e','f',
							  'g','h','i','j','k','l',
							  'm','n','o','p','r','s',
							  't','u','v','x','y','z',
							  'A','B','C','D','E','F',
							  'G','H','I','J','K','L',
							  'M','N','O','P','R','S',
							  'T','U','V','X','Y','Z',
							  '1','2','3','4','5','6',
							  '7','8','9','0');
	
	public function __construct($length=null)
	{
		if($length) self::$length=$length;
	}
	
	static public function generate($length=null)
	{
		if(!$length) $length=self::$length;
		$pass = "";
		$count=count(self::$alphabet) - 1;
		for($i = 0; $i < $length; $i++)
		{
		  $index = mt_rand(0, $count);
		  $pass .= self::$alphabet[$index];
		}
		return $pass;
	}
	
	static public function addSimbols($array)
	{
		array_merge(self::$alphabet, $array);
	}
	
	static public function setAlphabet($array)
	{
		self::$alphabet=$array;
	}
	
	static public function setLength($value)
	{
		self::$length=$value;
	}
	
	static public function getInstance()
	{
		$class = __CLASS__;
		return (self::$_instance !== null) ? self::$_instance : (self::$_instance = new $class);
	}
	
	public function __toString()
	{
		return self::generate();
	}
}